package stuMaiFrame;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID;

import com.rORM.core.MysqlQuery;
import com.rORM.core.Query;
import com.rORM.core.QueryFactory;

import database.Student;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import java.awt.event.ActionListener;
import java.time.format.DecimalStyle;
import java.awt.event.ActionEvent;

public class UpdateStuInfo extends JFrame {

	Student s = new Student();
	private JPanel contentPane;
	private JTextField name;
	private JTextField schooldepartment;
	private JTextField birth;
	private JTextField nation;
	private JTextField address;
	private JTextField nativePlace;
	private JTextField textField_8;
	private JTextField personalID;
	private String sex;
	private String politics;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		Query q = QueryFactory.createQuery();
		Student s = (Student)q.queryUniqueRow("select * from student where id = ?",Student.class, new Object[]{16402});
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					UpdateStuInfo frame = new UpdateStuInfo(s);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public UpdateStuInfo(Student s) {
		this.s = s;
		setVisible(true);
		setLocationRelativeTo(getOwner());
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 792, 472);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBorder(new EmptyBorder(5, 5, 5, 5));
		panel.setBounds(19, 6, 734, 460);
		contentPane.add(panel);
		
		JLabel label = new JLabel("姓名");
		label.setBounds(29, 89, 68, 29);
		panel.add(label);
		
		JLabel label_1 = new JLabel("学号");
		label_1.setBounds(29, 130, 68, 29);
		panel.add(label_1);
		
		JLabel label_2 = new JLabel("性别");
		label_2.setBounds(29, 171, 68, 29);
		panel.add(label_2);
		
		JLabel label_3 = new JLabel("院系");
		label_3.setBounds(29, 212, 68, 29);
		panel.add(label_3);
		
		JLabel label_4 = new JLabel("生日");
		label_4.setBounds(29, 253, 68, 29);
		panel.add(label_4);
		
		JLabel label_5 = new JLabel("入学时间");
		label_5.setBounds(29, 295, 68, 29);
		panel.add(label_5);
		
		JLabel label_6 = new JLabel("政治面貌");
		label_6.setBounds(29, 336, 68, 29);
		panel.add(label_6);
		
		JLabel label_7 = new JLabel("籍贯");
		label_7.setBounds(425, 89, 68, 29);
		panel.add(label_7);
		
		JLabel label_8 = new JLabel("家庭住址");
		label_8.setBounds(425, 130, 68, 29);
		panel.add(label_8);
		
		JLabel label_9 = new JLabel("国籍");
		label_9.setBounds(425, 171, 68, 29);
		panel.add(label_9);
		
		name = new JTextField(s.getName());
		name.setColumns(10);
		name.setBounds(114, 90, 130, 26);
		panel.add(name);
		
		schooldepartment = new JTextField(s.getSchool_department());
		schooldepartment.setColumns(10);
		schooldepartment.setBounds(109, 213, 130, 26);
		panel.add(schooldepartment);
		
		birth = new JTextField(s.getBirth());
		birth.setColumns(10);
		birth.setBounds(109, 254, 130, 26);
		panel.add(birth);
		
		nation = new JTextField(s.getNation());
		nation.setColumns(10);
		nation.setBounds(488, 172, 130, 26);
		panel.add(nation);
		
		address = new JTextField(s.getAdress());
		address.setColumns(10);
		address.setBounds(488, 130, 130, 26);
		panel.add(address);
		
		nativePlace = new JTextField(s.getNative_place());
		nativePlace.setColumns(10);
		nativePlace.setBounds(488, 90, 130, 26);
		panel.add(nativePlace);
	
		
		JRadioButton radioButton = new JRadioButton("男");
		radioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				sex = "男";
			}
		});
		radioButton.setBounds(94, 173, 83, 23);
		panel.add(radioButton);
		
		JRadioButton radioButton_1 = new JRadioButton("女");
		radioButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				sex = "女";
			}
		});
		radioButton_1.setBounds(204, 173, 83, 23);
		panel.add(radioButton_1);
		
		ButtonGroup bGroup  = new ButtonGroup();
		bGroup.add(radioButton);
		bGroup.add(radioButton_1);
		
		JRadioButton radioButton_2 = new JRadioButton("团员");
		radioButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				politics = "团员";
			}
		});
		radioButton_2.setBounds(94, 336, 83, 23);
		panel.add(radioButton_2);
		
		JRadioButton radioButton_3 = new JRadioButton("党员");
		radioButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				politics = "党员";
			}
		});
		radioButton_3.setBounds(204, 338, 83, 23);
		panel.add(radioButton_3);
		
		JRadioButton radioButton_4 = new JRadioButton("无");
		radioButton_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				politics = "无";
			}
		});
		radioButton_4.setBounds(312, 338, 83, 23);
		panel.add(radioButton_4);
		
		ButtonGroup bGroup2 = new ButtonGroup();
		bGroup2.add(radioButton_2);
		bGroup2.add(radioButton_3);
		bGroup2.add(radioButton_4);
		
		JButton button = new JButton("提交");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				s.setName(name.getText());
				s.setBirth(birth.getText());
				s.setAdress(address.getText());
				s.setNation(nation.getText());
				s.setPersonalID(Integer.valueOf(personalID.getText()));
				s.setNative_place(nativePlace.getText());
				s.setSchool_department(schooldepartment.getText());
				s.setSex(sex);
				s.setPolitics(politics);
				new MysqlQuery().update(s, new String[]{"id","name","school_department","sex","birth","personalID","college_time","politics","adress","Native_place","nation"});
				JOptionPane.showMessageDialog(null,"修改成功","信息提示框",JOptionPane.INFORMATION_MESSAGE);
			}
		});
		button.setBounds(555, 381, 117, 29);
		panel.add(button);
		
		JButton button_2 = new JButton("返回");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
			}
		});
		button_2.setBounds(214, 381, 117, 29);
		panel.add(button_2);
		
		JLabel label_10 = new JLabel("学生信息");
		label_10.setFont(new Font("Lucida Grande", Font.PLAIN, 25));
		label_10.setBounds(312, 27, 106, 31);
		panel.add(label_10);
		
		JLabel label_11 = new JLabel("(格式:xxxx-xx-xx)");
		label_11.setBounds(238, 259, 137, 16);
		panel.add(label_11);
		
		personalID = new JTextField(String.valueOf(s.getPersonalID()));
		personalID.setColumns(10);
		personalID.setBounds(488, 213, 130, 26);
		panel.add(personalID);
		
		JLabel label_12 = new JLabel("身份证号");
		label_12.setBounds(425, 212, 68, 29);
		panel.add(label_12);
		
		JLabel lblNewLabel = new JLabel(String.valueOf(s.getId()));
		lblNewLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 14));
		lblNewLabel.setBounds(109, 130, 117, 29);
		panel.add(lblNewLabel);
		
		JLabel label_13 = new JLabel(String.valueOf(s.getCollege_time()));
		label_13.setFont(new Font("Lucida Grande", Font.PLAIN, 14));
		label_13.setBounds(127, 295, 117, 29);
		panel.add(label_13);
	}
}
